//
//  User.m
//  LiWuShuo
//
//  Created by 袁小航 on 14/11/19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "User.h"
#import "Define.h"

@implementation User
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.userImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, USER_IMAGEVIEW_ORIGIN_Y, MAINVIEW_WIDTH, USER_IMAGEVIEW_ORIGIN_HEITH)];
        [_userImage setImage:[UIImage imageNamed:@"Me_ProfileBackground_iPad@2x.jpg"]];
        [self addSubview:_userImage];
        
        // 伪nav
        self.userTopNav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 64)];
        _userTopNav.backgroundColor = [UIColor clearColor];
        [self addSubview:_userTopNav];
        
        // nav title
        self.userTopNavTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, MAINVIEW_WIDTH, 30)];
        _userTopNavTitle.text = @"我的收藏";
        _userTopNavTitle.textColor = [UIColor whiteColor];
        _userTopNavTitle.textAlignment = YES;
        _userTopNavTitle.alpha = 0;
        [_userTopNav addSubview:_userTopNavTitle];
        
        //        定义一个头像的button
        self.headImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _headImageButton.backgroundColor = [UIColor clearColor];
        _headImageButton.frame = CGRectMake(MAINVIEW_WIDTH / 5 * 2,USER_IMAGEVIEW_ORIGIN_Y + 180, MAINVIEW_WIDTH / 5, MAINVIEW_WIDTH / 5);
        _headImageButton.layer.cornerRadius = _headImageButton.frame.size.width / 2;
        _headImageButton.layer.masksToBounds = YES;
        [_headImageButton setBackgroundImage:[UIImage imageNamed:@"collN.png"] forState:UIControlStateNormal];
        [_userImage addSubview:_headImageButton];

        //        定义一个现实登录名的Label
        self.headName = [[UILabel alloc]initWithFrame:CGRectMake(0, _headImageButton.frame.origin.y + 50, MAINVIEW_WIDTH, MAINVIEW_WIDTH / 5)];
        _headName.text = @"我的收藏";
        _headName.textAlignment = YES;
        _headName.textColor = [UIColor whiteColor];
        [_userImage addSubview:_headName];
//        在右上角设置“设置”按钮
        self.setButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _setButton.frame = CGRectMake(MAINVIEW_WIDTH * 0.9, 30, MAINVIEW_WIDTH * 0.07, MAINVIEW_WIDTH * 0.07);
        [_setButton setBackgroundImage:[UIImage imageNamed:@"iconfont-shezhi.png"] forState:UIControlStateNormal];
        [_userTopNav addSubview:_setButton];
        
//        创建userTableView
        [self createUserTableView];
        
    }
    return self;
}

#pragma mark - 创建userTableView
- (void)createUserTableView
{
    self.userTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, USER_FINAL_HIGHT,MAINVIEW_WIDTH, self.bounds.size.height - USER_FINAL_HIGHT) style:UITableViewStyleGrouped];
    
    [self addSubview:_userTableView];
    
    // 用一个透明的view作为tableview的headerview
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MAINVIEW_WIDTH, USER_DETAIL_HIGHT)];
    // 把它设为no不会渲染它，效率略高点儿，不明显
    view.opaque = NO;
    
    //  self.table.contentInset = UIEdgeInsetsMake(240, 0, 0, 0);  //没有用这个方法是因为UITableViewStylePlain的section title 会停留在DETAIL_HIGHT的位置
    _userTableView.tableHeaderView = view;

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
